from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from webdriver_manager.chrome import ChromeDriverManager


driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.implicitly_wait(10)

# 进入企业微信首页
driver.get("https://work.weixin.qq.com/")
# 点击-登录
driver.find_element(By.CLASS_NAME, "index_top_operation_loginBtn").click()

# # 睡眠30s等待扫码登录
# time.sleep(30)

# # 获取cookies
# print(driver.get_cookies())
# print(driver.current_url)

# 设置cookies绕过登录
my_cookies = [{'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.logined', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'true'}, {'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.cs_ind', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': ''}, {'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.vid', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1688858211371146'}, {'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wxpay.corpid', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1970325261984975'}, {'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.vid', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1688858211371146'}, {'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ref', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'direct'}, {'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.ltype', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '1'}, {'domain': '.work.weixin.qq.com', 'httpOnly': False, 'name': 'wwrtx.d2st', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'a8607177'}, {'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.refid', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '01811923'}, {'domain': '.work.weixin.qq.com', 'expiry': 1688999424, 'httpOnly': False, 'name': 'wwrtx.i18n_lan', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'zh'}, {'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.vst', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '7ag1HLNfrvET6edLj9LERTSKPlNoLIza_Bpr5E5ftidEvGIWFmncIguReZoMGl8cluJpAlfX5BmTnRzRtJpcQ45zrORIezPbyJhwX8eIc7g7x10JMC4YhV_6QeCSsce42UMTJx0F67uQyixhVytkTHueTZsG4VQPNDIvjWhbZSRn1u7wAz1rPfvorPQDx3hZ_Zv3I9iHcphKON6-G2P3sacjjptCtks8mBqb9HyANuFk_TL7rmInCS1z8iImXExdO6yaFl3rYdAUDvCfAycnnQ'}, {'domain': '.work.weixin.qq.com', 'httpOnly': True, 'name': 'wwrtx.sid', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': 'lanyrmqDIWwVSFavtSOE4Qtf80_DPVVkJeRkf-BHIxEUJUUckxuUwOLAjucF2aGY'}, {'domain': '.work.weixin.qq.com', 'expiry': 1717943411, 'httpOnly': False, 'name': 'wwrtx.c_gdpr', 'path': '/', 'sameSite': 'Lax', 'secure': False, 'value': '0'}]
for cookie in my_cookies:
    driver.add_cookie(cookie)

driver.get("https://work.weixin.qq.com/wework_admin/frame")
time.sleep(5)
driver.quit()